package cz.anime.ppro.beans;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import cz.anime.ppro.logic.MessageComponent;
import cz.anime.ppro.logic.UserComponent;
import cz.anime.ppro.model.Message;

@Component
@ManagedBean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class OutMessageBean {
	
	@Autowired
	private UserComponent userComponent;
	
	@Autowired
	private MessageComponent messageComponent;

	List<Message> messages;
	
	@PostConstruct
	private void init(){
		messages = messageComponent.getOutMessages(getCurrentUser());
	}
	
	private int getCurrentUser(){
		return userComponent.getUserByNick(userComponent.getCurrentUsernameFromSession()).getId();
	}

	public List<Message> getMessages() {
		return messages;
	}

	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}
}
